package com.qiankun.tang.ui.fragment.find;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.common.library.listener.OnAppListener;
import com.common.library.tools.Logger;
import com.common.library.ui.fragment.BaseRecyclerFragment;
import com.qiankun.tang.R;
import com.qiankun.tang.beans.ADBean;
import com.qiankun.tang.beans.VideoSynopsisBean;
import com.qiankun.tang.beans.items.ClassifyItem;
import com.qiankun.tang.ui.activity.PlayerActivity;
import com.qiankun.tang.ui.view.adapter.find.ClassifyAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author txf
 * @Title
 * @package com.qiankun.video.ui.fragment
 * @date 2017/6/12 0012
 */

public class ClassifyFragment extends BaseRecyclerFragment<ClassifyItem> implements OnAppListener.OnInteractionListener {
    List<String> xurls = new ArrayList<>();
    List<String> xtitles = new ArrayList<>();

    List<String> yurls = new ArrayList<>();
    List<String> ytitles = new ArrayList<>();


    List<String> furls = new ArrayList<>();
    private void startPlayerActivity(String id){
        startActivity(PlayerActivity.newIntent(id,getActivity()));
        getActivity().overridePendingTransition(R.anim.activity_zoomin,R.anim.activity_zoomout);
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAdapter(new ClassifyAdapter(getContext(), this));
        initData();
    }
    private void initData() {
        //分类
        String furi1 = "res:///" + R.drawable.find_f1;
        String furi2 = "res:///" + R.drawable.find_f2;
        String furi3 = "res:///" + R.drawable.find_f3;
        String furi4 = "res:///" + R.drawable.find_f4;
        String furi5 = "res:///" + R.drawable.find_f5;
        furls.add(furi1);
        furls.add(furi2);
        furls.add(furi3);
        furls.add(furi4);
        furls.add(furi5);

        //搞笑
        String xuri1 = "res:///" + R.drawable.find_x1;
        String xuri2 = "res:///" + R.drawable.find_x2;
        String xuri3 = "res:///" + R.drawable.find_x3;
        String xuri4 = "res:///" + R.drawable.find_x4;
        String xuri5 = "res:///" + R.drawable.find_x5;
        xurls.add(xuri1);
        xurls.add(xuri2);
        xurls.add(xuri3);
        xurls.add(xuri4);
        xurls.add(xuri5);
        String xtitle1 = "超强音效骗女友";
        String xtitle2 = "大人才能吃的巧克力";
        String xtitle3 = "对不起，我大姨夫来了";
        String xtitle4 = "献给高考生的毒鸡汤";
        String xtitle5 = "这样也算惊喜？！";
        xtitles.add(xtitle1);
        xtitles.add(xtitle2);
        xtitles.add(xtitle3);
        xtitles.add(xtitle4);
        xtitles.add(xtitle5);


        //音乐
        String yuri1 = "res:///" + R.drawable.find_y1;
        String yuri2 = "res:///" + R.drawable.find_y2;
        String yuri3 = "res:///" + R.drawable.find_y3;
        String yuri4 = "res:///" + R.drawable.find_y4;
        String yuri5 = "res:///" + R.drawable.find_y5;
        yurls.add(yuri1);
        yurls.add(yuri2);
        yurls.add(yuri3);
        yurls.add(yuri4);
        yurls.add(yuri5);
        String ytitle1 = "2016电影音乐混剪，听醉了";
        String ytitle2 = "日本宅男神曲《求交往》";
        String ytitle3 = "徐娇二次元#爱之诗#";
        String ytitle4 = "小黄人高能音乐创作";
        String ytitle5 = "男生吉他弹唱《女儿情》";
        ytitles.add(ytitle1);
        ytitles.add(ytitle2);
        ytitles.add(ytitle3);
        ytitles.add(ytitle4);
        ytitles.add(ytitle5);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }
    @Override
    protected void request(int pageIndex) {
        List<ClassifyItem> items = buildHomeItems();
        refreshData(items);
    }

    private List<ClassifyItem> buildHomeItems() {
        List<ClassifyItem> items = new ArrayList<>();
        //分类列表
        List<VideoSynopsisBean> videoSynopsisBeans2 = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            VideoSynopsisBean bean = new VideoSynopsisBean();
            bean.setImgUrl(furls.get(i));
            bean.setType(1);
            videoSynopsisBeans2.add(bean);
        }
        items.add(new ClassifyItem(ClassifyItem.TYPE_1, videoSynopsisBeans2));

        //分割线 7dp
        items.add(new ClassifyItem(ClassifyItem.TYPE_LINE, null));

        //ViewPager列表视图
        List<ADBean> adbeans = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            ADBean bean = new ADBean();
            bean.setType(0);
            bean.setId(i + "");
            bean.setImgUrl(yurls.get(i));
            bean.setTvtitle(ytitles.get(i));
            bean.setTvsubtitle("TV测试副标题 , " + i);
            bean.setSubtitle("聆听心中的美好");
            bean.setTitle("音乐");
            adbeans.add(bean);
        }
        items.add(new ClassifyItem(ClassifyItem.TYPE_0, adbeans));
        //分割线 7dp
        items.add(new ClassifyItem(ClassifyItem.TYPE_LINE, null));


        List<ADBean> adbeans2 = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            ADBean bean = new ADBean();
            bean.setType(0);
            bean.setId(i +"");
            bean.setImgUrl(xurls.get(i));
            bean.setTvtitle(xtitles.get(i));
            bean.setTvsubtitle("TV测试副标题 , " + i);
            bean.setSubtitle("精彩只在一瞬间");
            bean.setTitle("搞笑");
            adbeans2.add(bean);
        }
        items.add(new ClassifyItem(ClassifyItem.TYPE_0, adbeans2));
        return items;
    }

    @Override
    public void onInteraction(int type, Object o) {
        switch (type) {
            case ClassifyItem.TYPE_0:
                Logger.i("点击Item 类型为 0");
                startPlayerActivity("1");
                break;
            case ClassifyItem.TYPE_1:
                Logger.i("点击Item 类型为 1");
//                startPlayerActivity("2");
                break;
            case ClassifyItem.TYPE_2:
                Logger.i("点击Item 类型为 2");
                startPlayerActivity("2");
                break;
        }
    }
}
